var countdown=require('../public/javascripts/countdown'),sdc = require('sdc-clients')

var dc_config=require('../config/dc')['poc']
	,vmapi = new sdc.VMAPI(dc_config.vmapi)
module.exports = {
	get:function get(req, res) {
		if(req.headers.userid&&req.headers.userid!='null'){
					var options = {
						hostname: '192.168.115.239', 
						path: '/jobs/'+req.params.id,
						method: 'GET',
						headers: {"Accept": "application/json"}
					};
					require('http').request(options, function (resd) {
						var body = '';
						resd.setEncoding('utf8');
						resd.on('data',function(d){
							body += d;
						}).on('end', function(){
							var job=JSON.parse(body)
							if(job.execution==="running"||job.execution==="queued"){
								setTimeout(function(){get(req, res)},1000)
							}else{
								res.send({data:true})
							}
						});
					}).on('error', function(e) {
						
					}).end();
		}else res.send({path:'loginView.html'})
	}
}